package com.sogoodsoft.web.communicate;

import java.util.List;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.sogoodsoft.entity.common.Maillog;
import com.sogoodsoft.service.common.MaillogService;
import com.sogoodsoft.web.CrudActionSupport;
import com.sogoodsoft.web.WebConstants;

@Namespace("/mail")
@Results({ @Result(name = CrudActionSupport.RELOAD, location = "maillog.action", type = "redirect") })
public class MaillogAction extends CrudActionSupport < Maillog > {

    /**
	 * 
	 */
    private static final long serialVersionUID = 6716983298711868679L;

    private Long id;

    private Maillog maillog;

    private MaillogService mSer;

    private Page < Maillog > page = new Page < Maillog >(WebConstants.PAGE_SIZE);

    @Override
    public String delete() throws Exception {
        prepareModel();
        mSer.delete(maillog);
        addActionMessage(getText("delete.success"));
        return RELOAD;
    }

    @Override
    public String input() throws Exception {
        // TODO Auto-generated method stub
        return INPUT;
    }

    @Override
    public String list() throws Exception {
        List < PropertyFilter > filters = PropertyFilter.buildFromHttpRequest(Struts2Utils.getRequest());
        // 设置默认排序方式
        if (!page.isOrderBySetted()) {
            page.setOrderBy("id");
            page.setOrder(Page.ASC);
        }

        logger.debug("查询邮件列表");
        page = mSer.findPage(page, filters);
        return SUCCESS;
    }

    @Override
    protected void prepareModel() throws Exception {
        // TODO Auto-generated method stub
        if (id != null) {
            maillog = mSer.get(id);
        } else {
            maillog = new Maillog();
        }
    }

    @Override
    public String save() throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Maillog getModel() {
        // TODO Auto-generated method stub
        return this.maillog;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Maillog getMaillog() {
        return maillog;
    }

    public void setMaillog(Maillog maillog) {
        this.maillog = maillog;
    }

    public MaillogService getmSer() {
        return mSer;
    }

    @Autowired
    public void setmSer(MaillogService mSer) {
        this.mSer = mSer;
    }

    public Page < Maillog > getPage() {
        return page;
    }

    public void setPage(Page < Maillog > page) {
        this.page = page;
    }

}
